package com.njxzc.demo.controller.admin;

import com.njxzc.demo.common.http.ResponseResult;
import com.njxzc.demo.common.security.anno.AuthIgrone;
import com.njxzc.demo.entity.GoodsTypeEntity;
import com.njxzc.demo.service.admin.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/admin/type")
public class GoodsTypeController {
    @Autowired
    private GoodsTypeService goodsTypeService;

    @AuthIgrone //因为before的导航页需要查询商品类型
    @PostMapping("/getAllGoodsType")
    public ResponseResult<List<GoodsTypeEntity>> getAllGoodsType(){
        List<GoodsTypeEntity> goodsTypeList = goodsTypeService.list();
        return ResponseResult.getSuccessResult(goodsTypeList);
    }

    @AuthIgrone
    @PostMapping("/getGoodsType")
    public ResponseResult<Map<String, Object>> getGoodsType(@RequestBody GoodsTypeEntity goodsTypeEntity){
        return goodsTypeService.getGoodsType(goodsTypeEntity);
    }

    @AuthIgrone
    @PostMapping("/add")
    public ResponseResult<Map<String, Object>> add(@RequestBody GoodsTypeEntity goodsTypeEntity){
        return goodsTypeService.add(goodsTypeEntity);
    }

    @PostMapping("/update")
    public ResponseResult<Map<String, Object>> update(@RequestBody GoodsTypeEntity goodsTypeEntity){
        return goodsTypeService.update(goodsTypeEntity);
    }

    @PostMapping("/delete")
    public ResponseResult<Map<String, Object>> delete(@RequestBody GoodsTypeEntity goodsTypeEntity){
        return goodsTypeService.delete(goodsTypeEntity);
    }
}
